package cn.tedu.oa.approval.service.impl;

import cn.tedu.oa.approval.mapper.ApprovalMapper;
import cn.tedu.oa.approval.pojo.dto.ApprovalQuery;
import cn.tedu.oa.approval.pojo.dto.ApprovalSaveparm;
import cn.tedu.oa.approval.pojo.entity.Approval;
import cn.tedu.oa.approval.pojo.vo.ApprovalVO;
import cn.tedu.oa.approval.service.ApprovalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class ApprovalServiceImpl  implements ApprovalService {
    @Autowired
    ApprovalMapper approvalMapper;
    @Override
    public List<ApprovalVO> select(ApprovalQuery approvalQuery) {
        log.info("ApprovalServiceImpl.select()");
        List<ApprovalVO> list = approvalMapper.select(approvalQuery);
        return list;
    }

    @Override
    public void save(ApprovalSaveparm approvalSaveparm) {
        log.info("ApprovalServiceImpl.save()");
        Approval approval = new Approval();
        BeanUtils.copyProperties(approvalSaveparm,approval);
        if (approval.getId()==null){
            approval.setCreateTime(new Date());
            approvalMapper.insert(approval);
        }else{
            approval.setUpdateTime(new Date());
            approvalMapper.update(approval);
        }
    }
    @Override
    public void delete(Integer id) {
        log.info("ApprovalServiceImpl.delete()");
        approvalMapper.delete(id);

    }
}
